import axios from 'axios';
import Nprogress from 'nprogress';
import 'nprogress/nprogress.css'

//禁止小圆圈加载
Nprogress.configure({ showSpinner: false });

let request = axios.create({
   baseURL:'/mock',
   timeout: 5000,
});
request.interceptors.request.use((config)=>{
   Nprogress.start();
   return config;
},(error)=>{
   return Promise.reject(error);
});
request.interceptors.response.use((req)=>{
   if(req.status === 200) {
      Nprogress.done();
      return req.data;
   }else{
      alert('状态码非200');
   }
},(error)=>{
   if(error.code === 'ERR_BAD_REQUEST' ){
      alert(error.message);
   }
   return Promise.reject(error);
})

export default request;